package com.google.code.sapwcrawler.datahandler;

import com.google.code.sapwcrawler.data.Link;
import com.google.code.sapwcrawler.data.ParsedHtml;
import com.google.code.sapwcrawler.download.cycle.DownloadCycle;
import com.google.code.sapwcrawler.urlfilter.URLFilter;

import java.util.*;
import java.net.*;

public class CrawlerHandler implements DataHandler<ParsedHtml>
{
	private DownloadCycle cycle;
	private URLFilter urlFilter;
	public void setDownloadCycle(DownloadCycle v)
	{
		this.cycle = v;
	}
	
	public void setURLFilter(URLFilter v)
	{
		this.urlFilter = v;
	}
	
	public void processData(ParsedHtml data)
	{
		List<URL> list = new ArrayList<URL>();
		for(Link link: data.getLinks())	
			if(urlFilter.isDownloadableURL(link.getHref()))
				list.add(link.getHref());
		cycle.addUrls(list);
	}
}
